package com.adffice.sample.dbhelper;/**
 * 项目名称: DataBaseHelper
 * 文件名称: 
 * 创建时间: 2014/4/18
 * Copyright: 2014 www.fantasee.cn Inc. All rights reserved. 
 */

import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;

import com.adffice.library.dbhelper.DBConfig;
import com.adffice.library.dbhelper.DBHelper;
import com.adffice.sample.dbhelper.model.ItemEntity;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author Dallas.Cao </br> Create at 2014/4/18
 * @version 1.0
 */
public class DBHelperTestActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        DBConfig config = new DBConfig.Builder(this)
                .dbName("test.db")
                .dbVersion(3)
                .debug(true)
                .build();

        DBHelper.getInstance().init(config);
        DBHelper.getInstance().setUpgradeListener(new DBHelper.DbUpgradeListener() {
            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

            }
        });


        DBHelper dbHelper = DBHelper.getInstance();

        ItemEntity test = new ItemEntity();

        test.setBit((byte) 110);
        test.setBytes(new byte[110]);
        test.setCount(120);
        test.setGood(true);
        String id = UUID.randomUUID().toString();
        test.setId(id);
        test.setName("caobin" + id);
        test.setPrice(3.1415926);
        test.setWeight(59.8f);
       // test.setTime(new Date());
        test.setCc('C');

        dbHelper.insert(test);
        test.setCount(130);
        dbHelper.insert(test);
        test.setCount(140);
        dbHelper.insert(test);
        test.setCount(150);
        dbHelper.insert(test);
        test.setCount(160);
        dbHelper.insert(test);

        List<ItemEntity> list = dbHelper.query(ItemEntity.class);
        test.setPrice(1000);
        long count = dbHelper.update(test, null, null);
        list = dbHelper.query(ItemEntity.class);
        try {
            dbHelper.update(test, "count=?", new String[]{"120"});
        } catch (Exception e) {
            e.printStackTrace();
        }
        dbHelper.delete(ItemEntity.class, "id=?", new String[]{id});


    }
}
